package whu.o2o.adapter;

import java.util.ArrayList;

import whu.o2o.adapter.StudioAdapter.ViewHolder;
import whu.o2o.util.ConstantData;
import whu.o2o.vo.GuideVO;
import whu.o2o.vo.StudioVO;

import whu.o2o.R;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MyStudioAdapter extends BaseAdapter{
	private Activity mContext;
	private LayoutInflater mLayoutInflater;
	private ArrayList<GuideVO> mList;
	private Drawable mValidatedDrawable;

	public MyStudioAdapter(Activity context, ArrayList<GuideVO> list) {
		mContext = context;
		mList = list;
		mLayoutInflater = LayoutInflater.from(mContext);
		mValidatedDrawable = mContext.getResources().getDrawable(R.drawable.ic_route_selected);
		mValidatedDrawable.setBounds(0, 0, mValidatedDrawable.getMinimumWidth(), mValidatedDrawable.getMinimumHeight());
	}


	public int getCount() {
		return mList.size();
	}

	
	public Object getItem(int position) {
		return mList.get(position);
	}


	public long getItemId(int position) {
		return position;
	}

	
	public View getView(int position, View convertView, ViewGroup parent) {
		GuideVO guidevo = mList.get(position);

		ViewHolder holder;
		if (convertView == null) {
			convertView = mLayoutInflater.inflate(R.layout.mystudio_listview_item, null);

			holder = new ViewHolder();
			holder.userHead = (ImageView) convertView.findViewById(R.id.ico);
			holder.userName = (TextView) convertView.findViewById(R.id.tv_mystudio_name);
			holder.age = (TextView) convertView.findViewById(R.id.tv_mystudio_age);
		    holder.grade = (TextView) convertView.findViewById(R.id.tv_mystudio_jb);
			holder.qzico = (ImageView)convertView. findViewById(R.id.iv_mystudio_qzico);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		
		
		holder.userName.setText(guidevo.getName());
		holder.age.setText(guidevo.getAge());
		holder.grade.setText(guidevo.getGrade());
	
		
		if (ConstantData.Data.VALIDATED == guidevo.getValidated()) {
			holder.age.setCompoundDrawables(null, null, mValidatedDrawable, null);
		} else {
			holder.age.setCompoundDrawables(null, null, null, null);
		}

		return convertView;
	}

	static class ViewHolder {
		ImageView userHead;
		TextView userName;
		TextView age;//成员数
		//TextView sex;//关注人数
		TextView grade;//关注人数
		ImageView qzico;//群主标志
	}
}
